package ca.on.eho.qa.applogic1;

import org.openqa.selenium.WebDriver;

import ca.on.eho.qa.applogic.ApplicationManager;
import ca.on.eho.qa.applogic.ClientHelper;
import ca.on.eho.qa.applogic.UserHelper;
import ca.on.eho.qa.applogic.NavigationHelper;
import ca.on.eho.qa.applogic1.ClientHelper1;
import ca.on.eho.qa.applogic1.UserHelper1;
import ca.on.eho.qa.applogic1.NavigationHelper1;
import ca.on.eho.qa.util.Browser;
import ca.on.eho.qa.util.Constants;
import ca.on.eho.qa.util.PropertyLoader;
import ca.on.eho.qa.webdriver.WebDriverFactory;

public class ApplicationManager1 implements ApplicationManager {
	
	private UserHelper userHelper; 
	private ClientHelper clientHelper;
	private NavigationHelper navHelper;

	private WebDriver driver;
	private String baseUrl;

	public ApplicationManager1() {
		
	// Temporary replace http://10.245.40.205:10040/wps/portal	
	// with Google site
	baseUrl = PropertyLoader.loadProperty("site.url");
	String gridHubUrl = PropertyLoader.loadProperty("grid2.hub");

	Browser browser = new Browser();
	browser.setName(PropertyLoader.loadProperty("browser.name"));
	browser.setVersion(PropertyLoader.loadProperty("browser.version"));
	browser.setPlatform(PropertyLoader.loadProperty("browser.platform"));

	String username = PropertyLoader.loadProperty("user.username");
	String password = PropertyLoader.loadProperty("user.password");
	
	driver = WebDriverFactory.getInstance(gridHubUrl, browser, username, password);
	
	//Disabled implicit wait. We have to use explicit wait, when it is possible, to get more control on waiting.
	//driver.manage().timeouts().implicitlyWait(Constants.SHORT_WAIT, TimeUnit.SECONDS);

	userHelper = new UserHelper1(this); 
	clientHelper = new ClientHelper1(this);
	navHelper = new NavigationHelper1(this);
	
	getNavigationHelper().OpenMainPage();

	}

	@Override
	public UserHelper getUserHelper() {
		return userHelper;
	}

	@Override
	public ClientHelper getClientHelper() {
		return clientHelper;
	}
	
	@Override
	public NavigationHelper getNavigationHelper() {
		return navHelper;
	}

	@Override
	public void stop() {
		if (driver != null) {
			driver.quit();
		}
	}
	
	protected WebDriver getWebDriver() {
		return driver;
	}
	
	protected String getBaseUrl() {
		return baseUrl;
	}
	
}